#include "CAnimation.h"

CAnimation::CAnimation(void)
{
	CurrentFrame = 0;
	MaxFrames = 0;
	FrameInc = 1;
	FrameDelta = 100;
	OldTime = 0;
	Oscillate = false;
}

void CAnimation::OnAnimate()
{
	if(OldTime + FrameDelta > SDL_GetTicks())
		return;

	OldTime = SDL_GetTicks();

	CurrentFrame += FrameInc;

	if(Oscillate)
	{
		if(FrameInc > 0)
		{
			if(CurrentFrame >= MaxFrames)
				FrameInc = -FrameInc;
		}
		else{
			if(CurrentFrame <=0)
				FrameInc = -FrameInc;
		}
	}
	else{
		if(CurrentFrame >= MaxFrames)
			CurrentFrame = 0;
	}
}

void CAnimation::SetFrameRate(int Rate)
{
	FrameDelta = Rate;
}

void CAnimation::SetCurrentFrame(int Frame)
{
	if(Frame < 0 || Frame >= MaxFrames)
		return;

	CurrentFrame = Frame;
}

int CAnimation::GetCurrentFrame()
{
	return CurrentFrame;
}

